package com.zxl.always.on.display.tools;

import android.graphics.Typeface;

import com.zxl.always.on.display.ApplicationHelper;

/**
 * Created by Administrator on 2018/3/1.
 */

public class FontUtils {

    private static Typeface sTypeface;

    static final String[] ALL_FONT_ARRAYS = {
            "/system/fonts/SamsungSans-Bold.ttf", "/system/fonts/Roboto-Thin.ttf", "/system/fonts/Roboto-Light.ttf", "/system/fonts/Roboto-Regular.ttf", "/system/fonts/Roboto-Medium.ttf",
            "/system/fonts/RobotoCondensed-Light.ttf", "/system/fonts/RobotoCondensed-Regular.ttf", "/system/fonts/RobotoCondensed-Bold.ttf", "/system/fonts/SECRobotoLight-Bold.ttf",
            "/system/fonts/SECRobotoLight-Regular.ttf", "/system/fonts/RobotoNum-3L.ttf", "/system/fonts/SamsungSans-Num3T.ttf", "/system/fonts/Clock2017L.ttf", "/system/fonts/Clock2017R.ttf",
            "fonts/Clockopia.ttf"};


    public static Typeface getTypeface() {
        if (null == sTypeface) {
            for (String font : ALL_FONT_ARRAYS) {
                if (font.startsWith("/")) {
                    if (FileUtil.isFileExist(font)) {
                        try {
                            sTypeface = Typeface.createFromFile(font);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    try {
                        sTypeface = Typeface.createFromAsset(ApplicationHelper.getContext().getAssets(), font);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (sTypeface != null) {
                    LogUtils.d("font : " + font);
                    break;
                }
            }
        }
        return sTypeface;
    }
}
